<%@page import="com.shsh.safemanage.util.MessageUtil"%>
<%@page import="java.util.List"%>
<%@page import="com.shsh.safemanage.model.HSEMonthCompareReport"%>
<%@page import="com.shsh.safemanage.model.HSECategoryCause"%>
<%@page import="com.shsh.safemanage.util.Util"%>
<%@page import="com.shsh.safemanage.model.HSEReportUnit"%>
<%@page import="com.shsh.safemanage.model.Equipment"%>
<%@page import="com.shsh.safemanage.util.Constants"%>
<%@page import="com.shsh.safemanage.model.HSEReport"%>
<%@page import="com.shsh.safemanage.model.HSEMonthDetailReport"%>
<%@page language="java" pageEncoding="UTF-8"%>
<%@page import="java.util.Map"%>
<%@page import="com.shsh.safemanage.action.ActionCreator"%>
<%@page import="com.shsh.safemanage.action.BrowseHSEAction"%>
<%
	{
BrowseHSEAction browseAction = ActionCreator.createBrowseHSEAction();
HSEReport<HSEReportUnit> report = browseAction.browseHSEMonthReport(request);

if(report == null ){
	String errorKey = (String)request.getAttribute(Constants.REQUEST_ATTRIBUTE_ERROR);
	String errorMsg = MessageUtil.getMessage(errorKey);
	%>
<div align="center" style="font-size:14px;margin-top:10px;margin-bottom:10px;font-weight:bold; font-family:'微软雅黑','宋体';">
	该周期内无月报
</div>
<script type="text/javascript">
	$.dialog.alert('<%=errorMsg%>');
</script>
	<%
	return;
}

HSEMonthDetailReport<HSEReportUnit> monthDetailReport = report.getMonthDetailReport();
%>
<div align="center" style="width:99%;overflow-x:scroll;margin-left:3px;margin-top:5px;">
<table width="<%=monthDetailReport.getDangerActionCauseList().size()*110 + 80 %>px" border="1" cellpadding="0" cellspacing="0" style="font-size:12px;">
	<tr>
		<td class="a_text2" align="center" colspan="<%=monthDetailReport.getDangerActionCauseList().size() + 1%>">上海高桥分公司<%=Util.getDisplay(monthDetailReport.getDepartment1Name(), "") %>不安全行为HSE观察月报</td>
	</tr>
	<tr>
		<td class="a_text2" align="center">
		不安全行为分类
		</td>
		<%
		for(HSECategoryCause cause : monthDetailReport.getDangerActionCauseList()) {
		%>
		<td class="a_text2" align="center">
			<%=Util.getDisplay(cause.getCauseName(), "&nbsp;") %>
		</td>
		<%
		}
		%>
	</tr>
	<%
	int row = 0;
	int[][] dangerActionTable = monthDetailReport.getDangerActionTable();
	for (int rowIndex = 0; rowIndex < monthDetailReport.getUnitList().size(); rowIndex ++ ){
		row++;
		HSEReportUnit unit = monthDetailReport.getUnitList().get(rowIndex);
	%>
	<tr>
		<td class="a_text3" align="center"  style="width:80px;border-bottom:1px #E3E3E3 dashed;border-right:1px #E3E3E3 dashed; <%=(row % 2 == 1)? "background: #F8F8FF":"background: #DCDCDC"%>">
			<%=Util.getDisplay(unit.getReportUnitName(), "&nbsp;")%>
		</td>
		<%
			for(int columnIndex = 0; columnIndex < monthDetailReport.getDangerActionCauseList().size(); columnIndex ++ ){
		%>
		<td class="a_text3" align="center"  style="width:100px;border-bottom:1px #E3E3E3 dashed;border-right:1px #E3E3E3 dashed; <%=(row % 2 == 1)? "background: #F8F8FF":"background: #DCDCDC"%>">
			<%=dangerActionTable[rowIndex][columnIndex]%>
		</td>
		<%
			}
		%>
	</tr>
	<%
		}
	%>
</table>
</div>
<br/>
<div align="center">
<table border="1" cellpadding="0" cellspacing="0" style="font-size:12px;">
	<tr>
		<td class="a_text2" align="center" colspan="<%=monthDetailReport.getDangerStatusCauseList().size() + 1%>">上海高桥分公司<%=Util.getDisplay(monthDetailReport.getDepartment1Name(), "")%>不安全状态HSE观察月报</td>

	</tr>
	<tr>
		<td class="a_text2" align="center" >
		不安全状态分类
		</td>
		<%
			for(HSECategoryCause cause : monthDetailReport.getDangerStatusCauseList()) {
		%>
		<td class="a_text2" align="center" >
			<%=Util.getDisplay(cause.getCauseName(), "&nbsp;")%>
		</td>
		<%
			}
		%>
	</tr>
	<%
	 	row = 0;
		int[][] dangerStatusTable = monthDetailReport.getDangerStatusTable();
		for (int rowIndex = 0; rowIndex < monthDetailReport.getUnitList().size(); rowIndex ++ ){
			row++;
			HSEReportUnit unit = monthDetailReport.getUnitList().get(rowIndex);
	%>
	<tr>
		<td class="a_text3" align="center"  style="width:90px;border-bottom:1px #E3E3E3 dashed;border-right:1px #E3E3E3 dashed; <%=(row % 2 == 1)? "background: #F8F8FF":"background: #DCDCDC"%>">
			<%=Util.getDisplay(unit.getReportUnitName(), "&nbsp;")%>
		</td>
		<%
			for(int columnIndex = 0; columnIndex < monthDetailReport.getDangerStatusCauseList().size(); columnIndex ++ ){
				String columnWidth = "120";
				if(columnIndex == monthDetailReport.getDangerStatusCauseList().size() -1) {
					columnWidth = "50";
				}
		%>
		<td class="a_text3" align="center"  style="width:<%=columnWidth%>px;border-bottom:1px #E3E3E3 dashed;border-right:1px #E3E3E3 dashed; <%=(row % 2 == 1)? "background: #F8F8FF":"background: #DCDCDC"%>">
			<%=dangerStatusTable[rowIndex][columnIndex] %>
		</td>
		<%
			}
		%>
	</tr>
	<%
	}
	%>
</table>
</div>
<br/>
<div align="center" style="font-size:14px;">
HSE观察共<font style="text-decoration: underline;"> <%=monthDetailReport.getTotalCount() %> </font>条，其中：涉及不安全行为<font style="text-decoration: underline;"> <%=monthDetailReport.getDangerActionCount() %> </font>项和不安全状态<font style="text-decoration: underline;"> <%=monthDetailReport.getDangerStatusCount() %> </font>项的问题<font style="text-decoration: underline;"> <%=monthDetailReport.getDangerProblemCount() %> </font>条，观察正常<font style="text-decoration: underline;"> <%=monthDetailReport.getIsSolvedCount() %> </font>条，
确认已整改<font style="text-decoration: underline;"> <%=monthDetailReport.getIsProvedCount() %> </font>条，待整改<font style="text-decoration: underline;"> <%=monthDetailReport.getNotProvedCount() %> </font>条
</div>
<br/>
<br/>
<div align="center" style="margin-top:5px;">
<%
HSEMonthCompareReport<HSEReportUnit> previousCompareReport = report.getPreviousCompareReport();
HSEMonthCompareReport<HSEReportUnit> currentCompareReport = report.getCurrentCompareReport();
%>
<table border="1" cellpadding="0" cellspacing="0" style="font-size:12px;">
	<tr>
		<td rowspan="2"  class="a_text2" align="center">
		单位
		</td>
		<td colspan="2" class="a_text2" align="center">
		不安全行为
		</td>
		<td class="a_text2" align="center">
		幅度
		</td>
		<td colspan="2"  class="a_text2" align="center">
		不安全状态
		</td>
		<td class="a_text2" align="center">
		幅度
		</td>
		<td colspan="2" class="a_text2" align="center">
		不安全总数
		</td>
		<td class="a_text2" align="center">
		幅度
		</td>
	</tr>
	<tr>
		<td class="a_text2" align="center"><%=previousCompareReport.getYear() %>-<%=previousCompareReport.getMonth() %></td>
		<td class="a_text2" align="center"><%=currentCompareReport.getYear() %>-<%=currentCompareReport.getMonth() %></td>
		<td class="a_text2" align="center">%</td>
		<td class="a_text2" align="center"><%=previousCompareReport.getYear() %>-<%=previousCompareReport.getMonth() %></td>
		<td class="a_text2" align="center"><%=currentCompareReport.getYear() %>-<%=currentCompareReport.getMonth() %></td>
		<td class="a_text2" align="center">%</td>
		<td class="a_text2" align="center"><%=previousCompareReport.getYear() %>-<%=previousCompareReport.getMonth() %></td>
		<td class="a_text2" align="center"><%=currentCompareReport.getYear() %>-<%=currentCompareReport.getMonth() %></td>
		<td class="a_text2" align="center">%</td>
	</tr>
	
	<%

 	row = 0;
	int[][] previousTotalTable = previousCompareReport.getTotalTable();
	int[][] totalTable = currentCompareReport.getTotalTable();
	for (int rowIndex = 0; rowIndex < currentCompareReport.getUnitList().size(); rowIndex ++ ){
		row++;
		HSEReportUnit unit = currentCompareReport.getUnitList().get(rowIndex);
	%>
	<tr>
		<td class="a_text3" align="center"  style="width:100px;border-bottom:1px #E3E3E3 dashed;border-right:1px #E3E3E3 dashed; <%=(row % 2 == 1)? "background: #F8F8FF":"background: #DCDCDC"%>">
			<%=Util.getDisplay(unit.getReportUnitName(), "&nbsp;") %>
		</td>
		<%
		for(int columnIndex = 0; columnIndex < 3; columnIndex ++ ){
		%>
		<td class="a_text3" align="center"  style="width:65px;border-bottom:1px #E3E3E3 dashed;border-right:1px #E3E3E3 dashed; <%=(row % 2 == 1)? "background: #F8F8FF":"background: #DCDCDC"%>">
		<%=previousTotalTable[rowIndex][columnIndex] %>
		</td>
		<td class="a_text3" align="center"  style="width:65px;border-bottom:1px #E3E3E3 dashed;border-right:1px #E3E3E3 dashed; <%=(row % 2 == 1)? "background: #F8F8FF":"background: #DCDCDC"%>">
		<%=totalTable[rowIndex][columnIndex] %>
		</td>
		<td class="a_text3" align="center"  style="width:50px;border-bottom:1px #E3E3E3 dashed;border-right:1px #E3E3E3 dashed; <%=(row % 2 == 1)? "background: #F8F8FF":"background: #DCDCDC"%>">
		<%=Util.getRange(totalTable[rowIndex][columnIndex], previousTotalTable[rowIndex][columnIndex]) %>
		</td>
		<%
		}
		%>
	</tr>
	<%
	}
	%>
</table>
</div>

<br/>
<br/>
<div style="width:99%;overflow-x:scroll;margin-left:3px;margin-top:5px;margin-bottom:5px;">
<table width="<%=currentCompareReport.getUnitList().size()*180+150 %>px"  border="1" cellpadding="0" cellspacing="0" style="font-size:12px;">
	<tr>
		<td rowspan="2" class="a_text2" align="center">
		不安全行为分类
		</td>
		<%	
		for (int columnIndex = 0; columnIndex < currentCompareReport.getUnitList().size(); columnIndex ++ ){
			HSEReportUnit unit = currentCompareReport.getUnitList().get(columnIndex);
		%>
		<td colspan="2" class="a_text2" align="center" style="width:130px;">
			<%=Util.getDisplay(unit.getReportUnitName(), "&nbsp;") %>
		</td>
		<td class="a_text2" align="center" style="width:50px;">
		幅度
		</td>
		<%
		}
		%>
	</tr>
	<tr>
		<%	
		for (int columnIndex = 0; columnIndex < currentCompareReport.getUnitList().size(); columnIndex ++ ){
			HSEReportUnit unit = currentCompareReport.getUnitList().get(columnIndex);
		%>
		<td class="a_text2" align="center" style="width:65px;"><%=previousCompareReport.getYear() %>-<%=previousCompareReport.getMonth() %></td>
		<td class="a_text2" align="center" style="width:65px;"><%=currentCompareReport.getYear() %>-<%=currentCompareReport.getMonth() %></td>
		<td class="a_text2" align="center" style="width:50px;">%</td>
		<%
		}
		%>
	</tr>
	
	<%
 	row = 0;
	int[][] previousCompareDangerActionTable = previousCompareReport.getDangerActionTable();
	int[][] currentCompareDangerActionTable = currentCompareReport.getDangerActionTable();
	for(int rowIndex = 0 ; rowIndex < currentCompareReport.getDangerActionCauseList().size(); rowIndex ++) {
		row++;
		HSECategoryCause cause = currentCompareReport.getDangerActionCauseList().get(rowIndex);
	%>
	<tr>
		<td class="a_text3" align="center" style="width:110px;border-bottom:1px #E3E3E3 dashed;border-right:1px #E3E3E3 dashed; <%=(row % 2 == 1)? "background: #F8F8FF":"background: #DCDCDC"%>">
			<%=Util.getDisplay(cause.getCauseName(), "&nbsp;") %>
		</td>
		<%
		for (int columnIndex =0 ; columnIndex < currentCompareReport.getUnitList().size(); columnIndex++ ){
		%>
		<td class="a_text3" align="center"  style="width:65px;border-bottom:1px #E3E3E3 dashed;border-right:1px #E3E3E3 dashed; <%=(row % 2 == 1)? "background: #F8F8FF":"background: #DCDCDC"%>">
		<%=previousCompareDangerActionTable[rowIndex][columnIndex] %>
		</td>
		<td class="a_text3" align="center"  style="width:65px;border-bottom:1px #E3E3E3 dashed;border-right:1px #E3E3E3 dashed; <%=(row % 2 == 1)? "background: #F8F8FF":"background: #DCDCDC"%>">
		<%=currentCompareDangerActionTable[rowIndex][columnIndex] %>
		</td>
		<td class="a_text3" align="center"  style="width:50px;border-bottom:1px #E3E3E3 dashed;border-right:1px #E3E3E3 dashed; <%=(row % 2 == 1)? "background: #F8F8FF":"background: #DCDCDC"%>">
		<%=Util.getRange(currentCompareDangerActionTable[rowIndex][columnIndex], previousCompareDangerActionTable[rowIndex][columnIndex]) %>
		</td>
		<%
		}
		%>
	</tr>
	<%
	}
	%>
	<!-- 不安全状态 -->
	<tr>
		<td rowspan="2" class="a_text2" align="center">
		不安全状态分类
		</td>
		<%	
		for (int columnIndex = 0; columnIndex < currentCompareReport.getUnitList().size(); columnIndex ++ ){
			HSEReportUnit unit = currentCompareReport.getUnitList().get(columnIndex);
		%>
		<td colspan="2" class="a_text2" align="center">
			<%=Util.getDisplay(unit.getReportUnitName(), "&nbsp;") %>
		</td>
		<td class="a_text2" align="center">
		幅度
		</td>
		<%
		}
		%>
	</tr>
	<tr>
		<%	
		for (int columnIndex = 0; columnIndex < currentCompareReport.getUnitList().size(); columnIndex ++ ){
			HSEReportUnit unit = currentCompareReport.getUnitList().get(columnIndex);
		%>
		<td class="a_text2" align="center" style="width:65px;"><%=previousCompareReport.getYear() %>-<%=previousCompareReport.getMonth() %></td>
		<td class="a_text2" align="center" style="width:65px;"><%=currentCompareReport.getYear() %>-<%=currentCompareReport.getMonth() %></td>
		<td class="a_text2" align="center" style="width:50px;">%</td>
		<%
		}
		%>
	</tr>
	
	<%
 	row = 0;
	int[][] previousCompareDangerStatusTable = previousCompareReport.getDangerStatusTable();
	int[][] currentCompareDangerStatusTable = currentCompareReport.getDangerStatusTable();
	for(int rowIndex = 0 ; rowIndex < currentCompareReport.getDangerStatusCauseList().size(); rowIndex ++) {
		row++;
		HSECategoryCause cause = currentCompareReport.getDangerStatusCauseList().get(rowIndex);
	%>
	<tr>
		<td class="a_text3" align="center"  style="width:110px;border-bottom:1px #E3E3E3 dashed;border-right:1px #E3E3E3 dashed; <%=(row % 2 == 1)? "background: #F8F8FF":"background: #DCDCDC"%>">
			<%=Util.getDisplay(cause.getCauseName(), "&nbsp;") %>
		</td>
		<%
		for (int columnIndex =0 ; columnIndex < currentCompareReport.getUnitList().size(); columnIndex++ ){
		%>
		<td class="a_text3" align="center"  style="width:65px;border-bottom:1px #E3E3E3 dashed;border-right:1px #E3E3E3 dashed; <%=(row % 2 == 1)? "background: #F8F8FF":"background: #DCDCDC"%>">
		<%=previousCompareDangerStatusTable[rowIndex][columnIndex] %>
		</td>
		<td class="a_text3" align="center"  style="width:65px;border-bottom:1px #E3E3E3 dashed;border-right:1px #E3E3E3 dashed; <%=(row % 2 == 1)? "background: #F8F8FF":"background: #DCDCDC"%>">
		<%=currentCompareDangerStatusTable[rowIndex][columnIndex] %>
		</td>
		<td class="a_text3" align="center"  style="width:50px;border-bottom:1px #E3E3E3 dashed;border-right:1px #E3E3E3 dashed; <%=(row % 2 == 1)? "background: #F8F8FF":"background: #DCDCDC"%>">
		<%=Util.getRange(currentCompareDangerStatusTable[rowIndex][columnIndex], previousCompareDangerStatusTable[rowIndex][columnIndex]) %>
		</td>
		<%
		}
		%>
	</tr>
	<%
	}

	row++;
	%>
	<!-- 合计 -->
	<tr>
		<td class="a_text3" align="center"  style="width:110px;border-bottom:1px #E3E3E3 dashed;border-right:1px #E3E3E3 dashed; <%=(row % 2 == 1)? "background: #F8F8FF":"background: #DCDCDC"%>">
			合计
		</td>
		<%
		for (int columnIndex =0 ; columnIndex < currentCompareReport.getUnitList().size(); columnIndex++ ){
			int previousHeji = previousCompareDangerActionTable[previousCompareDangerActionTable.length-1][columnIndex] + previousCompareDangerStatusTable[previousCompareDangerStatusTable.length-1][columnIndex];
			int currentHeji = currentCompareDangerActionTable[currentCompareDangerActionTable.length-1][columnIndex] + currentCompareDangerStatusTable[currentCompareDangerStatusTable.length-1][columnIndex];
		%>
		<td class="a_text3" align="center"  style="width:65px;border-bottom:1px #E3E3E3 dashed;border-right:1px #E3E3E3 dashed; <%=(row % 2 == 1)? "background: #F8F8FF":"background: #DCDCDC"%>">
		<%=previousHeji %>
		</td>
		<td class="a_text3" align="center"  style="width:65px;border-bottom:1px #E3E3E3 dashed;border-right:1px #E3E3E3 dashed; <%=(row % 2 == 1)? "background: #F8F8FF":"background: #DCDCDC"%>">
		<%=currentHeji %>
		</td>
		<td class="a_text3" align="center"  style="width:50px;border-bottom:1px #E3E3E3 dashed;border-right:1px #E3E3E3 dashed; <%=(row % 2 == 1)? "background: #F8F8FF":"background: #DCDCDC"%>">
		<%=Util.getRange(currentHeji, previousHeji) %>
		</td>
		<%
		}
		%>
	</tr>	
</table>
</div>
<br/>
<div align="left" style="margin-left:30%;font-size:14px;">
造成上述<font style="text-decoration: underline;"> <%=Util.getDisplay(currentCompareReport.getTotalCauseCount(), "0") %> </font>项不安全行为/状态的间接原因有如下：
<%
List<HSECategoryCause> remoteCauseList = currentCompareReport.getRemoteCauseList();
int[][] remoteCauseTable = currentCompareReport.getRemoteCauseTable();
for(int i=0;i<remoteCauseList.size();i++){
	HSECategoryCause remoteCause = remoteCauseList.get(i);
%>
<br/>
<%=i+1 %>）“<%=Util.getDisplay(remoteCause.getCauseName(), "") %>”共<font style="text-decoration: underline;"> <%=Util.getDisplay(remoteCauseTable[i][0], "0") %> </font>项，占<font style="text-decoration: underline;"> <%=Util.getDisplay(Util.formatGrade(remoteCauseTable[i][1]), "0")%> </font>%；
<%
}
%>
</div>
<%
}
%>
